<script type="text/javascript">	
	var user_select = "<?=$user_select;?>";
</script>

<?php if ($updates && !$showCompleted):?>

<h3>Actions for <?=$contact->firstname;?> <?=$contact->surname;?></h3>

<table>
<thead>
	<tr>
		<th>Action</th><th>Action Date</th><th>Task Owner</th><th>Notes</th><th>Completed</th>
	</tr>
</thead>
<tbody>
<?php foreach ($updates as $key => $update):?>
	<tr>
		<td class="edit_textinput" id="<?=$update->id;?>|contactaction|action_title"><?=$update->action_title;?></td>
		<td class="edit_dateinput" id="<?=$update->id;?>|contactaction|actiondate"><?= date("d/m/Y", strtotime($update->actiondate)); ?></td>
		<td class="edit_userselect" id="<?=$update->id;?>|contactaction|ownerid"><?php if (strlen($update->owner_firstname) || strlen($update->owner_lastname)):?><?=$update->owner_firstname;?> <?=$update->owner_lastname;?><?php else:?>None assigned<?php endif;?></td>
		<td class="edit_textarea" id="<?=$update->id;?>|contactaction|action_notes"><?=$update->action_notes;?></td>
		<td class="edit_yesno" id="<?=$update->id;?>|contactaction|completed"><?php if ($update->completed):?>Yes<?php else:?>No<?php endif;?></td>
	</tr>
<?php endforeach;?>
</tbody>
</table>

<?php endif;?>

<p><?php if ($completed_updates && !$showCompleted):?><a href="<?=site_url('companies/showContactActions/'.$contact->id.'/'.$company->id.'/1');?>">Show Completed Actions</a></p><?php endif;?>

<?php if ($completed_updates && $showCompleted):?>

<h3>Completed Actions for <?=$contact->firstname;?> <?=$contact->surname;?></h3>

<table>
<thead>
	<tr>
		<th>Action</th><th>Action Date</th><th>Owner</th><th>Notes</th><th>Completed</th>
	</tr>
</thead>
<tbody>
<?php foreach ($completed_updates as $key => $update):?>
	<tr>
		<td class="edit_textinput" id="<?=$update->id;?>|contactaction|action_title"><?=$update->action_title;?></td>
		<td class="edit_dateinput" id="<?=$update->id;?>|contactaction|actiondate"><?= date("d/m/Y", strtotime($update->actiondate)); ?></td>
		<td class="edit_userselect" id="<?=$update->id;?>|contactaction|ownerid"><?php if (strlen($update->owner_firstname) || strlen($update->owner_lastname)):?><?=$update->owner_firstname;?> <?=$update->owner_lastname;?><?php else:?>None assigned<?php endif;?></td>
		<td class="edit_textarea" id="<?=$update->id;?>|contactaction|action_notes"><?=$update->action_notes;?></td>
		<td class="edit_yesno" id="<?=$update->id;?>|contactaction|completed"><?php if ($update->completed):?>Yes<?php else:?>No<?php endif;?></td>
	</tr>
<?php endforeach;?>
</tbody>
</table>
<?php endif;?>

<p><?php if ($updates && $showCompleted):?><a href="<?=site_url('companies/showContactActions/'.$contact->id.'/'.$company->id);?>">Show Outstanding Actions</a></p><?php endif;?>

<?=form_open('companies/addContactActions/'.$contact->id.'/'.$company->id);?>
<fieldset>
	<legend>Set An Action for <?=$contact->firstname;?> <?=$contact->surname;?></legend>
	<dl>
		<dt><label for="action_title" class="required">Task</label></dt>
		<dd><input type="text" name="action_title" id="action_title" /</dd>
		<dt><label for="actiondate" class="required">Action Date</label></dt>
		<dd><input type="text" name="actiondate" id="actiondate" class="datePicker" /></dd>
		<dt><label for="ownerid" class="required">Owner</label></dt>
		<dd><select name="ownerid" id="ownerid">
				<?php foreach ($users as $user):?>
					<option value="<?=$user->id;?>" <?php if($user->id == $this->authentication->getuserId()):?>selected="selected"<?php endif;?>><?=$user->firstname.' '.$user->lastname;?></option>
				<?php endforeach;?>
			</select></dd>
	</dl>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="Add Action" class="button" />
</fieldset>
<?=form_close();?>